﻿using System.Collections.Generic;
using System.Windows;
using System.Windows.Controls;

namespace FazaDemo.PL.Wpf
{
    abstract class AddPanelBuilder
    {

        protected AddElementBuilder _elementBuilder;

        protected AddPanelBuilder()
        {
            
        }

        public void Build(TabItem tabItem)
        {
            IList<string> fieldTexts = GetFieldTexts();
            var grid = new Grid();
            for (int i = 0; i < 2; i++)
            {
                grid.ColumnDefinitions.Add(new ColumnDefinition { Width = GridLength.Auto });    
            }
            for (int i = 0; i < fieldTexts.Count + 1; i++)
            {
                grid.RowDefinitions.Add(new RowDefinition {Height = GridLength.Auto});
            }
            _elementBuilder = new AddElementBuilder(grid);
            var saveButton = new Button{Content = "Сохранить"};
            grid.Children.Add(saveButton);
            Grid.SetColumn(saveButton, 0);
            Grid.SetRow(saveButton, 0);
            for (int i = 0; i < fieldTexts.Count; i++)
            {
                _elementBuilder.Build(fieldTexts[i], i + 1);
            }
            tabItem.Content = grid;
        }

        protected abstract IList<string> GetFieldTexts();

    }
}
